package action.admin;

import service.securite.DroitsAcces;
import service.securite.Erreur;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * Servlet implementation class AdminDeconnexionServlet
 */
public class AdminDeconnexionAction extends Action {
	private static final long serialVersionUID = 1L;
	
	protected void initSession(HttpServletRequest request )
	{
		HttpSession session = request.getSession();
	}
    
    public static boolean aLesDroits(HttpServletRequest request) {
    	return DroitsAcces.isAdmin(request);
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	public ActionForward execute(final ActionMapping pMapping,
			ActionForm pForm, final HttpServletRequest pRequete,
			HttpServletResponse pReponse) {
		
		this.initSession(pRequete);
		
		if (!aLesDroits(pRequete)) {
			//Erreur.setErreurDroitsAdmin(request, response, getServletContext());
			//return;
		}
		
		if (!DroitsAcces.deconnexionAdmin(pRequete, pReponse)) {
			//Erreur.setErreurAdmin(request, response, getServletContext(), "Erreur lors de la deconnexion.");
			//return;
		}
		
		pRequete.getSession().removeAttribute("isAdmin");
		return pMapping.findForward("success");
		//response.sendRedirect("Accueil");
		//return;
	}


}
